package croe.jdbc.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * User: zengzhili
 * Time: 2014-07-02 20:38
 */
public class AppContextSupport implements ApplicationContextAware {

    private static ApplicationContext appContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appContext = applicationContext;
    }

    public static ApplicationContext getAppContext() {
        if (appContext == null) {
            synchronized (AppContextSupport.class) {
                if (appContext == null) {
                    appContext = new ClassPathXmlApplicationContext("classpath*:spring/**/*.xml");
                }
            }
        }
        return appContext;
    }
}
